﻿#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
//
//void menu()
//{
//	printf("**********************************\n");
//	printf("********1:加         2:减*********\n");
////	printf("********3:乘         4:除*********\n");
////	printf("*************0:退出***************\n");
////	printf("**********************************\n");
////}
////
////int add(int x, int y)
////{
////	return x + y;
////}
////
////int sub(int x, int y)
////{
////	return x - y;
////}
////
////int mul(int x, int y)
////{
////	return x * y;
////}
////
////int div(int x, int y)
////{
////	return x / y;
////}
////
////int main()
////{
////	int x, y;
////	int input;
////	int ret;
////	int (*p[5])(int, int) = { 0,add,sub,mul,div };
////	printf("计算器！\n");
////	do
////	{
////		menu();
////		scanf("%d", &input);
////		
////		if ((input <= 4 && input >= 1))
////		{
////			printf("输入操作数：");
////			scanf("%d%d", &x, &y);
////			ret = (*p[input])(x, y);
////			printf("ret = %d\n", ret);
////		}
////		else if (input == 0)
////		{
////			printf("退出计算器\n");
////		}
////		else
////		{
////			printf("输入有误\n");
////		}
////	} while (input);
////	return 0;
////}
//
//void Find(int arr[], int* p1, int* p2,int sz)
//{
//	int tmp = 0;
//	for (int i = 0; i < sz;i++)
//	{
//		tmp ^= arr[i];
//	}
//	int pos = 0;
//	for (int i = 0; i < 32; i++)
//	{
//		if ((tmp >> i) & 1 == 1)
//		{
//			pos = i;
//			break;
//		}
//	}
//	for (int i = 0; i < sz;i++)
//	{
//		if ((arr[i] >> pos) & 1 == 1)
//		{
//			*p1 ^= arr[i];
//		}
//		else
//		{
//			*p2 ^= arr[i];
//		}
//	}
//}
//
//int main()
//{
//	int a = 0, b = 0;
//	int arr[] = {1,2,3,4,5,1,2,3,4,6};
//	int sz = sizeof(arr) / sizeof(arr[0]);
//	Find(arr, &a, &b,sz);
//	printf("%d %d", a, b);
//	
//	return 0;
//}
#include <stdio.h>

int year(int b)
{
	if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)
		return 31;
	else if (b == 2)
		return 28;
	else
		return 30;
}
int day(int a, int b)
{
	if (((a % 4 == 0 & a % 100 != 0) || a % 400 == 0) && b == 2)
	{
		return 29;
	}
	else
	{
		return year(b);
	}
}

int main()
{
	int a, b;
	while (scanf("%d %d", &a, &b) != EOF)
	{
		int r = day(a, b);
		printf("%d\n", r);
	}
	return 0;
}